import { getCookie } from '@/utils/cookie'
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import common from './modules/common'
import Store from '../store/index'

const routes: Array<RouteRecordRaw> = [

  {
    path: '/',
    redirect: '/main'
  },
  {
    path: '/main',
    name: 'Main',
    redirect: '/main/home',
    component: () => import('../views/main/Main.vue'),
    children: [
      {
        path: '/main/about', component: import('../views/About.vue'), name: 'About', meta: {
          title: '首页'
        }
      },
      {
        path: '/main/home', component: import('../views/Home.vue'), name: 'Home', meta: {
          title: '首页'
        }
      },
      {
        path: '/main/UploadMusic', component: import('../views/UploadMusic.vue'), name: 'UploadMusic', meta: {
          title: '音乐上传'
        }
      }, {
        path: '/main/UserAdmin', component: import('../views/user/UserAdmin.vue'), name: 'UserAdmin', meta: {
          title: '用户管理'
        }
      },{
        path: '/main/MusicAdmin', component: import('../views/music/MusicAdmin.vue'), name: 'MusicAdmin', meta: {
          title: '音乐管理'
        },
        
      },{
        path: '/main/MusicMenuAdmin', component: import('../views/music/MusicMenuAdmin.vue'), name: 'MusicMenuAdmin', meta: {
          title: '歌单管理'
        },
      },

      

    ]
  },
  ...common,
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})




router.beforeEach((to, from, next) => {
  if (to.path != "/login") {
    // if (!getCookie("token")) {
    //   router.push("/login")
    // }
    //Store.commit("common/setMenu_width", "MAX");

    // Store.commit('common/addLable_list', [{ path: to.path, name: to.meta.title }])
    // Store.commit('common/addLable_list', [{ path: to.path, name: to.meta.title }])
    // Store.commit('common/addLable_list', [{ path: to.path, name: to.meta.title }])
    // Store.commit('common/addLable_list', [{ path: to.path, name: to.meta.title }])
    // Store.commit('common/addLable_list', [{ path: to.path, name: to.meta.title }])
    // //Store.commit('common/removeLable_list', 0)
    // Store.state.common.lable_list
    // console.log( Store.state.common.lable_list)
  }
  next()
})


export default router
